package com.cskaoyan.service;

import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.model.MarketBrand;
import com.cskaoyan.model.MarketBrandExample;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author zoe ling
 * @Date 2024/6/8
 */
@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    MarketBrandMapper brandMapper;
    @Override
    public List<MarketBrand> list(int page, int limit) {
        PageHelper.startPage(page, limit);
        MarketBrandExample example = new MarketBrandExample();
        example.createCriteria().andDeletedEqualTo(false);
        example.setOrderByClause("add_time desc");
        List<MarketBrand> brandList = brandMapper.selectByExample(example);
        return brandList;
    }

    @Override
    public MarketBrand findById(Integer brandId) {
        MarketBrandExample example = new MarketBrandExample();
        example.createCriteria().andIdEqualTo(brandId)
                .andDeletedEqualTo(false);
        List<MarketBrand> brandList = brandMapper.selectByExample(example);
        //三目表达式
        return brandList!=null&&brandList.size()==1?brandList.get(0):null;

    }
}
